package com.luo.dao.impl;

import com.luo.dao.ClassMappers;
import com.luo.dao.GoodMappers;
import com.luo.model.GoodByTwoClassId;
import com.luo.model.Goods;
import com.luo.model.OneClass;
import com.luo.model.TwoClass;
import com.luo.util.SqlSessionUtil;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.session.SqlSession;

import java.util.List;
import java.util.Map;

/**
 * 功能：
 * 作者：Luo。
 * 日期：2024/1/9 19:53
 */
public class GoodMappersImpl implements GoodMappers {
    //查询最新的商品
    public List<Goods> queryNewGoods() {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        GoodMappers mapper = sqlSession.getMapper(GoodMappers.class);
        List<Goods> goods = mapper.queryNewGoods();
        sqlSession.close();
        return goods;
    }

    //根据二级目录id查询商品
    @Override
    public List<Goods> queryGoodsByTwoId(final String id) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        GoodMappers mapper = sqlSession.getMapper(GoodMappers.class);
        List<Goods> goods = mapper.queryGoodsByTwoId(id);
        sqlSession.close();
        return goods;
    }

    @Override
    public List<Goods> queryAllGoods() {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        GoodMappers mapper = sqlSession.getMapper(GoodMappers.class);
        List<Goods> goods = mapper.queryAllGoods();
        sqlSession.close();
        return goods;
    }

    @Override
    public int updateGood(Goods goods) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        GoodMappers mapper = sqlSession.getMapper(GoodMappers.class);
        int rows = mapper.updateGood(goods);
        sqlSession.commit();
        sqlSession.close();
        return rows;
    }

    @Override
    public int deleteGoodById(String id) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        GoodMappers mapper = sqlSession.getMapper(GoodMappers.class);
        int rows = mapper.deleteGoodById(id);
        sqlSession.commit();
        sqlSession.close();
        return rows;
    }

    @Override
    public int deleteSomeGoodsById(List<String> strings) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        GoodMappers mapper = sqlSession.getMapper(GoodMappers.class);
        int rows = mapper.deleteSomeGoodsById(strings);
        sqlSession.commit();
        sqlSession.close();
        return rows;
    }

    @Override
    public int addOneGood(final Goods goods) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        GoodMappers mapper = sqlSession.getMapper(GoodMappers.class);
        int rows = mapper.addOneGood(goods);
        sqlSession.commit();
        sqlSession.close();
        return rows;
    }

    @Override
    public List<Goods> queryGoodSomeByTwoClassId(GoodByTwoClassId goodByTwoClassId) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        GoodMappers mapper = sqlSession.getMapper(GoodMappers.class);
        List<Goods> goods = mapper.queryGoodSomeByTwoClassId(goodByTwoClassId);
        sqlSession.close();
        return goods;
    }

    @Override
    public List<Goods> queryGoodByOneId(String id) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        GoodMappers mapper = sqlSession.getMapper(GoodMappers.class);
        List<Goods> goods = mapper.queryGoodByOneId(id);
        sqlSession.close();
        return goods;
    }

    @Override
    public Goods queryGoodBy(String id) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        GoodMappers mapper = sqlSession.getMapper(GoodMappers.class);
        Goods goods = mapper.queryGoodBy(id);
        sqlSession.close();
        return goods;
    }

    @Override
    public int addIntroducepictureImgs(final Map map) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        GoodMappers mapper = sqlSession.getMapper(GoodMappers.class);
        int i = mapper.addIntroducepictureImgs(map);
        sqlSession.commit();
        sqlSession.close();
        return i;
    }

    @Override
    public int addMainpicturesImgs(final Map map) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        GoodMappers mapper = sqlSession.getMapper(GoodMappers.class);
        int i = mapper.addMainpicturesImgs(map);
        sqlSession.commit();
        sqlSession.close();
        return i;
    }

    @Override
    public List<Goods> queryGoodsByNameLike(String name) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        GoodMappers mapper = sqlSession.getMapper(GoodMappers.class);
        List<Goods> goods = mapper.queryGoodsByNameLike(name);
        sqlSession.commit();
        sqlSession.close();
        return goods;
    }
}
